package com.service.business.support;


import com.service.business.base.constants.RedisLockConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.validation.constraints.NotNull;

@Slf4j
@Component
public class MemberMerchantLockUtils extends RedissonLockUtils {

    public boolean lockCreateMerchant(@NotNull Integer memberId) {
        return super.lock(buildCreateMerchantLock(memberId));
    }

    public void unlockCreateMerchant(@NotNull Integer memberId) {
        super.unlock(buildCreateMerchantLock(memberId));
    }


    public static String buildCreateMerchantLock(Integer memberId) {
        return RedisLockConstant.MEMBER_MERCHANT + memberId;
    }

    public static String buildOrderLock(String orderNo) {
        return RedisLockConstant.MEMBER_MERCHANT_ORDER + orderNo;
    }

    public static String buildCreditLineLock(Integer merchantId, String coins) {
        return RedisLockConstant.MEMBER_MERCHANT_CREDIT_LINE + merchantId + RedisLockConstant.INTERVAL + coins;
    }


}
